package hoan.nguyen.webapp.controller;

import java.security.Principal;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Horizon
 * 
 */
@Controller
@RequestMapping
public class WelcomeController {

	@RequestMapping(value = "/welcome")
	public ModelAndView welcome(Principal principal) {

		ModelAndView model = new ModelAndView("welcome");
		
		String name = principal.getName();
		model.addObject("name", name);
		model.addObject("username", name);
		model.addObject("message", "message");

		return model;
	}

	@RequestMapping(value="/login", method = RequestMethod.GET)
	public String login(ModelMap model) {
 
		return "login";
 
	}
 
	@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
	public String loginerror(ModelMap model) {
 
		model.addAttribute("error", "true");
		return "login";
 
	}
 
	@RequestMapping(value="/logout", method = RequestMethod.GET)
	public String logout(ModelMap model) {
 
		return "login";
 
	}
}
